/*
 * @Description: 全屏查看大图
 * @Version: V1.0.0
 * @Author: 黄鑫
 * @Date: 2025-05-07
 * @LastEditors: 黄鑫
 * @LastEditTime: 2025-07-23
 * @FilePath: hx_image_preview_page.dart
 * @Remarks: 
 */

import 'package:extended_image/extended_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/route_manager.dart';

class HxImagePreviewPage extends StatelessWidget {
  final String imageUrl;
  const HxImagePreviewPage(this.imageUrl, {super.key});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => Get.back(),
      child: Scaffold(
        backgroundColor: Colors.black,
        body: ExtendedImage.network(
          imageUrl,
          fit: BoxFit.contain,
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().screenHeight,
          enableSlideOutPage: true,
          mode: ExtendedImageMode.gesture,
          loadStateChanged: (state) {
            if (state.extendedImageLoadState == LoadState.loading) {
              return Container(
                  width: double.infinity,
                  height: double.infinity,
                  color: const Color(0xFFEAEAEA),
                  child: const CupertinoActivityIndicator());
            }
            if (state.extendedImageLoadState == LoadState.failed) {
              return Container(
                width: double.infinity,
                height: double.infinity,
                alignment: Alignment.center,
                color: const Color(0xFFEAEAEA),
                child: Text(
                  "加载失败",
                  style: TextStyle(
                    fontSize: 10,
                  ),
                ),
              );
            }
            return null;
          },
          initGestureConfigHandler: (_) => GestureConfig(
            minScale: 1.0,
            maxScale: 4.0,
            animationMinScale: 0.8,
            animationMaxScale: 4.5,
            speed: 1.0,
            inertialSpeed: 100.0,
            initialScale: 1.0,
            inPageView: false,
          ),
        ),
      ),
    );
  }
}
